package com.tongji.housediy.utils
{
	import com.tongji.housediy.view.components.AbstractBorderChild;
	import com.tongji.housediy.view.components.AbstractDrawingRoom;
	import com.tongji.housediy.view.components.Furniture;
	import com.tongji.housediy.view.components.IndependentFloor;
	import com.tongji.housediy.view.components.InteriorWall;
	import com.tongji.housediy.view.components.NormalDoor;
	import com.tongji.housediy.view.components.NormalWindow;
	import com.tongji.housediy.view.components.OpeningWall;
	import com.tongji.housediy.view.components.RoomBorder;
	import com.tongji.housediy.view.components.RoomFloor;
	import com.tongji.housediy.view.components.RoomShape;
	import com.tongji.housediy.view.components.SpecificRoom;
	import com.tongji.housediy.vo.Goods;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.controls.Image;
	import mx.core.DragSource;
	import mx.core.IFlexDisplayObject;
	import mx.core.UIComponent;
	import mx.managers.DragManager;

	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class DragDropManager
	{
		static private var ds:DragSource;
		
		static public function startDragRoomChild(dragInitiator:UIComponent, event:MouseEvent, type:String):void
		{
			ds = new DragSource();
			
			var proxy:UIComponent;
			
			switch (type)
			{
				case "wallFormat":
					proxy = new InteriorWall();
					break;
				case "independentFloor":
					proxy = new IndependentFloor();
					break;
			}
			
			var multipler:Number = MathCalculation.getZoomMultiple();
			proxy.scaleX = multipler;
			proxy.scaleY = multipler;
			
			ds.addData(proxy, type);
			DragManager.doDrag(dragInitiator, ds, event, proxy, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
		
		/**
		 * 拖拽创建 门、窗、开放墙、内墙和独立地板
		 * @param dragInitiator 启动拖拽的组件
		 * @param event
		 * @param type 用来区别创建哪种类型的元件
		 * 
		 */		
		static public function startDragBorderChild(dragInitiator:UIComponent, event:MouseEvent, type:String, proxy:AbstractBorderChild):void
		{
			ds = new DragSource();
			
			var multipler:Number = MathCalculation.getZoomMultiple();
			proxy.scaleX = multipler;
			proxy.scaleY = multipler;
			
			ds.addData(proxy, type);
			DragManager.doDrag(dragInitiator, ds, event, proxy, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
		
		static public function startDragFurniture(dragInitiator:UIComponent, event:MouseEvent, furniture:Furniture):void
		{
			ds = new DragSource();
			
			//var furniture:Furniture = new Furniture(goods, content);
			var multipler:Number = MathCalculation.getZoomMultiple();
			furniture.scaleX = multipler;
			furniture.scaleY = multipler;
			
			ds.addData(furniture, "furnitureFormat");
			DragManager.doDrag(dragInitiator, ds, event, furniture, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
		
		/**
		 * 拖拽创建 不同类型的 房间
		 * @param dragInitiator 启动拖拽的组件
		 * @param event
		 * @param roomType 用来区别创建哪种形状的房间
		 * 
		 */		
		static public function startDragRoom(dragInitiator:UIComponent, event:MouseEvent, roomProxy:AbstractDrawingRoom):void
		{
			ds = new DragSource();
			
			//var roomProxy:AbstractDrawingRoom = new SpecificRoom(roomIndex);
			var multipler:Number = MathCalculation.getZoomMultiple();
			roomProxy.scaleX = multipler;
			roomProxy.scaleY = multipler;
			
			ds.addData(roomProxy, "roomFormat");
			DragManager.doDrag(dragInitiator, ds, event, roomProxy, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
		
		/**
		 * 拖拽创建 各种类型的扩展墙
		 * @param dragInitiator 启动拖拽的组件
		 * @param event
		 * @param src 拖拽代理图片的路径
		 * 
		 */		
		static public function startDragExpandedWall(dragInitiator:UIComponent, event:MouseEvent, src:String):void
		{
			ds = new DragSource();
			
			var imageProxy:Image = new Image();
			imageProxy.load(src);
			imageProxy.width = 50;
			imageProxy.height = 50;
			
			ds.addData(src, "expandFormat");
			DragManager.doDrag(dragInitiator, ds, event, imageProxy, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
		
		static public function startDragFloorMap(dragInitiator:UIComponent, event:MouseEvent, content:BitmapData, hostGoods:Goods):void
		{
			ds = new DragSource();
			
			var imageProxy:Image = new Image();
			imageProxy.source = new Bitmap(content);
			imageProxy.width = content.width;
			imageProxy.height = content.height;
			
			var transferData:Array = [content, hostGoods];
			
			ds.addData(transferData, "mapFormat");
			DragManager.doDrag(dragInitiator, ds, event, imageProxy, -dragInitiator.mouseX, -dragInitiator.mouseY);
		}
	}
}